
package com.idealighter.game.games.texaspoker.handler;

import com.idealighter.game.core.annotation.ResMsgHandler;
import com.idealighter.game.gamehall.dto.MemInfo;
import com.idealighter.game.gamehall.dto.TableInfo;
import com.idealighter.game.games.texaspoker.TexaspokerPlayer;
import com.idealighter.game.games.texaspoker.message.ResEnterRoomMsg;
import com.idealighter.game.message.core.ResMessage;
import com.idealighter.game.robot.common.PlayerPosition;
import com.idealighter.game.robot.core.Player;
import com.idealighter.game.robot.handler.ResMessageHandler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


@ResMsgHandler(505202)
public class ResEnterRoomHandler implements ResMessageHandler {

  private static final Logger LOG = LoggerFactory.getLogger(ResEnterRoomHandler.class);

  @Override
  public void action(Player player, ResMessage message) {

    player.position = PlayerPosition.ROOM;
    LOG.info("[德州扑克]玩家[{}][{}]进入房间[{}]成功", player.userName, player.playerId, player.roomId);
    TexaspokerPlayer texaspokerPlayer = (TexaspokerPlayer) player;
    texaspokerPlayer.tables.clear();
    texaspokerPlayer.members.clear();

    ResEnterRoomMsg msg = (ResEnterRoomMsg) message;

    for (TableInfo table : msg.getTables()) {
      texaspokerPlayer.tables.put(table.getId(), table);
    }

    for (MemInfo member : msg.getMembers()) {
      texaspokerPlayer.members.put(member.getPlayerId(), member);
    }
    texaspokerPlayer.enterTable();
  }
}
